   
function [encoded_data]= encode_PAA(seg_width,data)

% seg_width=10;
% data=origdata(1,:);

%break_points=[realmin -1.5341205 -1.1503494 -0.8871466 -0.6744898 -0.4887764 -0.3186394 -0.1573107  0.0000000  0.1573107  0.3186394 0.4887764  0.6744898  0.8871466  1.1503494  1.5341205 realmax];
break_points=[-realmax -1.5341205 -1.1503494 -0.8871466 -0.6744898 -0.4887764 -0.3186394 -0.1573107  0.0000000  0.1573107  0.3186394 0.4887764  0.6744898  0.8871466  1.1503494  1.5341205 realmax];

num_codeword=size(break_points,2)-1;

tmp=truncwidth(seg_width,data);

for i=1:size(tmp,1)
    seg_mean=mean(tmp(i,:));
    for j=1:num_codeword
        if and(seg_mean>break_points(j),seg_mean<break_points(j+1))
            encoded_data(i)=j;
            break
        end
    end    
end

